﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace WindowsGame1
{
    class Bolinha: Objeto2D
    {
        float speed;
        ShotManager shotManager;

        public const float SPEED = 4f;


        public Bolinha(Vector2 posicao, Color cor, Texture2D textura)
            : base(posicao, cor, textura)
        {
            //Origem = new Vector2(Retangulo.Width / 2, Retangulo.Height / 2);
        }
        public void Update(GameTime gameTime)
        {
            
            if (Input.GetKey(Keys.A))
            {
                Posicao = new Vector2(Posicao.X - 0.1f, Posicao.Y);
            }
            else if (Input.GetKey(Keys.D))
            {
                Posicao = new Vector2(Posicao.X + 0.1f, Posicao.Y);
            }

            if (Input.GetKey(Keys.W) && speed < SPEED)
            {
                Posicao = new Vector2(Posicao.Y - 0.1f, Posicao.X);
            }
            else if (Input.GetKey(Keys.S)  && Math.Abs(speed) < SPEED)
            {
                Posicao = new Vector2(Posicao.Y + 0.1f, Posicao.X);
            }
            else if (speed > SPEED)
                speed = SPEED;
            else if (speed < -SPEED)
                speed = -SPEED;
            else
            {
                if (speed > 0)
                {
                    speed -= 0.1f;
                }
                else if (speed < 0)
                {
                    speed += 0.1f;
                }
                if (Math.Abs(speed) <= 0.1f)
                {
                    speed = 0;
                }
            }
            CheckBounds();

        }

        public void CheckBounds()
        {
            if (!Game1.GWindow.ClientBounds.Intersects(this.Retangulo))
            {
                if (Posicao.X > Game1.GWindow.ClientBounds.Width)
                {
                    Posicao = new Vector2(0, Posicao.Y);
                }
                else if (Posicao.Y > Game1.GWindow.ClientBounds.Height)
                {
                    Posicao = new Vector2(Posicao.X, 0);
                }
                else if (Posicao.X < 0)
                {
                    Posicao = new Vector2(Game1.GWindow.ClientBounds.Width, Posicao.Y);
                }
                else if (Posicao.Y < 0)
                {
                    Posicao = new Vector2(Posicao.X, Game1.GWindow.ClientBounds.Height);
                }
            }
        }
        //public override void Draw(SpriteBatch spriteBatch)
        //{
        //    base.Draw(spriteBatch);

        //}

    }
}
